<?php

namespace App\Http\Middleware;

use Closure, Auth, Redirect, Route;

class AuthenticateSettle
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param \Illuminate\Http\Request $request
     * @return string
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->guest()) {
            if ($request->ajax() || $request->wantsJson()) {
                return abort('401');
            } else {
                return Redirect::guest(route('wx.settle.login'));
            }
        }
        return $next($request);

    }
}
